<template>
  <div class='home'>
    <el-container>
      <el-header>
        <div class="headerLeft">
          <img src="https://pic56.photophoto.cn/20200705/0007019911115622_b.jpg">
          <span>bob后台管理系统</span>
        </div>
        <div class="headerright">
          <el-button
            type="info"
            @click="quit"
          >退出</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside  :style="{width: isCollapsed ? '64px':'200px'}">
            <div class="togglePanel" @click="togglePanel">|||</div>
          <el-col :span="24">
            <el-menu
              :default-active="activePath"
              class="el-menu-vertical-demo"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#ffd04b"
              unique-opened
              :collapse-transition="false"
              :collapse='isCollapsed'
              router
            >
              <el-submenu
                :index="'/'+item.path"
                v-for="item in menus"
                :key="item.id"
              >
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{item.authName}}</span>
                </template>
                <el-menu-item
                  :index="'/'+subItem.path"
                  v-for="subItem in item.children"
                  :key="subItem.id"
                  @click="changeActivePath('/'+subItem.path)"
                >{{subItem.authName}}</el-menu-item>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-aside>
        <el-main>
            
            <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  components: {},
  data() {
    return {
      menus: [],
      isCollapsed: false,
      activePath:'/users',
    };
  },
  methods: {
    quit() {
      this.$router.replace("/login");
      window.sessionStorage.removeItem("token");
    },
    async getMenuList() {
      const {data:menuList} = await this.$http.get("menus");
      console.log(menuList);
      if (menuList.meta.status == "200") {
        this.menus = menuList.data;
        // this.$router.push(this.activePath);
      } else {
        this.$message(menuList.meta.msg);
      }
    },
    togglePanel(){
        this.isCollapsed=!this.isCollapsed;
    },
    changeActivePath(path){
        
        window.sessionStorage.setItem('activePath',path)
    },
    getActivePath(){
        this.activePath=window.sessionStorage.getItem('activePath');
        this.$router.push( this.activePath);
        
    }
  },
  created() {
    this.getMenuList();
    this.getActivePath();
  },
};
</script>
<style lang='scss' scoped>
.home,
::v-deep .el-container {
  height: 100%;
}
::v-deep header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .headerLeft {
    display: flex;
    justify-content: space-between;
    align-items: center;
    img {
      margin-right: 10px;
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }
  }
}
.el-menu{
    border: none;
    
}

::v-deep .el-header {
  background: gray;
}
::v-deep .el-aside {
  background: gray;
  height: 100%;
  transition: width 0.3s ease; 
  
  .togglePanel{
      background:lightgray;
      letter-spacing: 2px;
      text-align: center;
      line-height: 30px;
      height:30px;
      cursor: pointer;
  }
}

.el-main{
    background:rgba(1,1,1,0.1);
}
</style>